package top.wettis.chat.service.impl;

import cn.dev33.satoken.stp.StpUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import top.wettis.chat.constant.ResultType;
import top.wettis.chat.mapper.TaskMapper;
import top.wettis.chat.pojo.DO.Task;
import top.wettis.chat.pojo.VO.Result;
import top.wettis.chat.pojo.VO.TaskVO;
import top.wettis.chat.service.ITaskService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;
import java.util.stream.Collectors;

/**
 * <p>
 * 任务表 服务实现类
 * </p>
 *
 * @author wettis
 * @since 2023-03-25
 */
@Service
public class TaskServiceImpl extends ServiceImpl<TaskMapper, Task> implements ITaskService {

    @Override
    public Result<Object> getTask() {
        List<Task> tasks = getBaseMapper().selectList(new LambdaQueryWrapper<Task>().eq(Task::getUserId, StpUtil.getLoginIdAsInt()));
        List<TaskVO> task = new ArrayList<>();
        for (Task a:tasks) {
           task.add(new TaskVO(){{
               setTask_id(a.getTaskId());
               setType(String.valueOf(a.getType()));
               setDetil(a.getDetil());
               setUser_id(a.getUserId());
           }});
        }
        return Result.successInfo(ResultType.GET,task);
    }
}
